package com.yuxi.Dao.Impl;

import java.io.Serializable;
import java.util.List;

import org.springframework.stereotype.Repository;

import com.yuxi.Dao.OwnWordRecordDao;
import com.yuxi.Entity.InformationClassification;
import com.yuxi.Request.OwnQuery;
import com.yuxi.Request.Page;
import com.yuxi.excelEntity.OwnWordRecord;
@Repository
public class OwnWordRecordDaoImpl  extends BaseDaoImpl<Serializable, Serializable> implements OwnWordRecordDao  {
	
	
	public OwnWordRecordDaoImpl(){
		super(OwnWordRecord.class);
	}
	@Override
	public void add(OwnWordRecord oRecord) {
		super.add(oRecord);
	}

	@Override
	public OwnWordRecord get(Integer oId) {
		try{
			return (OwnWordRecord) super.find(" from OwnWordRecord where id=?",oId).get(0);
		}catch(Exception e){
			return null;
		}
	}

	@Override
	public List<OwnWordRecord> getALl() {
		try{
			return (List<OwnWordRecord>) super.find(" from OwnWordRecord ");
		}catch(Exception e){
			return null;
		}
	}

	@Override
	public List<OwnWordRecord> getByUserId(Integer userId) {
		try{
			return (List<OwnWordRecord>) super.find(" from OwnWordRecord where createUserId=? ",userId);
		}catch(Exception e){
			return null;
		}
	}

	@Override
	public void modify(OwnWordRecord oRecord) {
		super.update(oRecord);
	}

	@Override
	public void del(OwnWordRecord oRecord) {
		super.delete(oRecord);
	}
	@Override
	public Page<OwnWordRecord> getOwnWordListByQuery(OwnQuery query, Page<OwnWordRecord> p) {		
		
		if(query.getUserAB()!=null&&!query.getUserAB().isEmpty()){			
			return super.splitPageQuery("from OwnWordRecord where state=? and prisonId=? and createTime BETWEEN ? and ? and"
					+ " (createUserName=? or userBName=?) order by createTime desc ", p,query.getState(),query.getPrisnoId(),query.getStartTime(),query.getEndTime(),query.getUserAB(),query.getUserAB());
		}else{	
			if(query.getDelPower()==1){
				return super.splitPageQuery("from OwnWordRecord where prisonId=? and createTime BETWEEN ? and ?  order by createTime desc", p,query.getPrisnoId(),query.getStartTime(),query.getEndTime());
			}
			return super.splitPageQuery("from OwnWordRecord where state=? and prisonId=? and createTime BETWEEN ? and ?  order by createTime desc", p,query.getState(),query.getPrisnoId(),query.getStartTime(),query.getEndTime());
		}
	}

}
